/*
 * Account.java
 *
 * Created on 2 2007 0:15
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.persistent.entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity class Account
 * 
 * @author alexog
 */
@Entity
@Table(name = "account")
@NamedQueries( {
        @NamedQuery(name = "Account.findById", query = "SELECT a FROM Account a WHERE a.id = :id"),
        @NamedQuery(name = "Account.findByEmail", query = "SELECT a FROM Account a WHERE a.email = :email"),
        @NamedQuery(name = "Account.findByLocale", query = "SELECT a FROM Account a WHERE a.locale = :locale"),
        @NamedQuery(name = "Account.findByUsername", query = "SELECT a FROM Account a WHERE a.username = :username"),
        @NamedQuery(name = "Account.findByCreationDate", query = "SELECT a FROM Account a WHERE a.creationDate = :creationDate"),
        @NamedQuery(name = "Account.findByLastname", query = "SELECT a FROM Account a WHERE a.lastname = :lastname"),
        @NamedQuery(name = "Account.findBySecurityQuestion", query = "SELECT a FROM Account a WHERE a.securityQuestion = :securityQuestion"),
        @NamedQuery(name = "Account.findByFirstname", query = "SELECT a FROM Account a WHERE a.firstname = :firstname"),
        @NamedQuery(name = "Account.findBySecurityAnswer", query = "SELECT a FROM Account a WHERE a.securityAnswer = :securityAnswer")
    })
public class Account implements Serializable {

    @Id
    @Column(name = "ID", nullable = false)
    @GeneratedValue
    private Integer id;

    @Column(name = "email")
    private String email;

    @Column(name = "locale")
    private String locale;

    @Column(name = "username", nullable = false)
    private String username;

    @Column(name = "creationDate")
    @Temporal(TemporalType.DATE)
    private Date creationDate;

    @Column(name = "lastname")
    private String lastname;

    @Column(name = "securityQuestion")
    private String securityQuestion;

    @Column(name = "firstname")
    private String firstname;

    @Column(name = "securityAnswer")
    private String securityAnswer;
    
    @OneToMany(mappedBy = "account")
    private Collection<Tank> tankCollection;
    
    /** Creates a new instance of Account */
    public Account() {
    }

    /**
     * Creates a new instance of Account with the specified values.
     * @param id the id of the Account
     */
    public Account(Integer id) {
        this.id = id;
    }

    /**
     * Creates a new instance of Account with the specified values.
     * @param id the id of the Account
     * @param username the username of the Account
     */
    public Account(Integer id, String username) {
        this.id = id;
        this.username = username;
    }

    /**
     * Gets the id of this Account.
     * @return the id
     */
    public Integer getId() {
        return this.id;
    }

    /**
     * Sets the id of this Account to the specified value.
     * @param id the new id
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * Gets the email of this Account.
     * @return the email
     */
    public String getEmail() {
        return this.email;
    }

    /**
     * Sets the email of this Account to the specified value.
     * @param email the new email
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * Gets the locale of this Account.
     * @return the locale
     */
    public String getLocaleString() {
        return this.locale;
    }

    /**
     * Sets the locale of this Account to the specified value.
     * @param locale the new locale
     */
    public void setLocaleString(String locale) {
        this.locale = locale;
    }

    /**
     * Gets the username of this Account.
     * @return the username
     */
    public String getUsername() {
        return this.username;
    }

    /**
     * Sets the username of this Account to the specified value.
     * @param username the new username
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * Gets the creationDate of this Account.
     * @return the creationDate
     */
    public Date getCreationDate() {
        return this.creationDate;
    }

    /**
     * Sets the creationDate of this Account to the specified value.
     * @param creationDate the new creationDate
     */
    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    /**
     * Gets the lastname of this Account.
     * @return the lastname
     */
    public String getLastname() {
        return this.lastname;
    }

    /**
     * Sets the lastname of this Account to the specified value.
     * @param lastname the new lastname
     */
    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    /**
     * Gets the securityQuestion of this Account.
     * @return the securityQuestion
     */
    public String getSecurityQuestion() {
        return this.securityQuestion;
    }

    /**
     * Sets the securityQuestion of this Account to the specified value.
     * @param securityQuestion the new securityQuestion
     */
    public void setSecurityQuestion(String securityQuestion) {
        this.securityQuestion = securityQuestion;
    }

    /**
     * Gets the firstname of this Account.
     * @return the firstname
     */
    public String getFirstname() {
        return this.firstname;
    }

    /**
     * Sets the firstname of this Account to the specified value.
     * @param firstname the new firstname
     */
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    /**
     * Gets the securityAnswer of this Account.
     * @return the securityAnswer
     */
    public String getSecurityAnswer() {
        return this.securityAnswer;
    }

    /**
     * Sets the securityAnswer of this Account to the specified value.
     * @param securityAnswer the new securityAnswer
     */
    public void setSecurityAnswer(String securityAnswer) {
        this.securityAnswer = securityAnswer;
    }

    /**
     * Gets the tankCollection of this Account.
     * @return the tankCollection
     */
    public Collection<Tank> getTankCollection() {
        return this.tankCollection;
    }

    /**
     * Sets the tankCollection of this Account to the specified value.
     * @param tankCollection the new tankCollection
     */
    public void setTankCollection(Collection<Tank> tankCollection) {
        this.tankCollection = tankCollection;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes 
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this Account.  The result is 
     * <code>true</code> if and only if the argument is not null and is a Account object that 
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Account)) {
            return false;
        }
        Account other = (Account)object;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs 
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "com.persistent.entity.Account[id=" + id + "]";
    }

    public void setLocale(Locale locale) {
        this.setLocaleString(locale.getCountry());
    }    
    
    public Locale getLocale() {
        return new Locale(this.getLocaleString());
    }
}
